<?php
//--模型
class Con_model_db extends Acan{
	
	public $defaultAct='tables';
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
		$this->model = Afun_db()->model(Acan_table_model);
	}
	
	//添加
	function Act_add(){
		include $this->Atpl();
	}
	function Act_up(){
		$model = $this->model->findPk($this->id);
		include $this->Atpl();
	}
	
	function Act_save(){
		$save = $_POST['save'];
		if($this->id){
			$rs = $this->model->updatePk($save,$this->id);
		}else{
			$rs = $this->model->save($save);
		}
		if($rs==1){
			$msg = '更新成功';
		}elseif($rs==0){
			$msg = '没有更新';
		}else{
			$msg = '更新失败';
		}
		echo $msg;
	}
	
	function Act_tables(){
		$this->cache_name = 'Asale-model_db-acolumn';
		$acolumn = Afun_cache_get($this->cache_name);
		$acolumn_arr = array('Name'=>'表名','Engine'=>'表类型','Row_format'=>'格式','Rows'=>'行','Data_length'=>'数据长度','Index_length'=>'索引长度','Auto_increment'=>'自动递增值','Comment'=>'注释');
		if(!is_array($acolumn)){$acolumn = $acolumn_arr;}
		if($_POST['acolumn']){
			$acolumn = $_POST['acolumn'];
			Afun_cache_set($this->cache_name,$acolumn);//写入缓存
		}
		$query = Afun_db()->query('SHOW TABLE STATUS');
		$column = $query->fetchObject();
		$tables = $query->fetchAll();
		include $this->Atpl();
	}
	//--结构浏览
	function Act_structure(){
		$model = Afun_db()->model($this->id);
		include $this->Atpl();
	}
	
}

?>